// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © honeydev9598

//@version=5
indicator("SuperTrend Dual RMA", overlay=true, max_labels_count=500)
rma1_length = input.int(14, "RMA 1 Length", minval=1)
rma2_length = input.int(21, "RMA 2 Length", minval=1)
atr_period  = input.int(14, "ATR Period", minval=1)
atr_mult    = input.float(2.0, "ATR Multiplier", step=0.1)
rma1 = ta.rma(hlc3 * volume, rma1_length) / ta.rma(volume, rma1_length)
rma2 = ta.rma(hlc3 * volume, rma2_length) / ta.rma(volume, rma2_length)
atr = ta.atr(atr_period)
basis = (rma1 + rma2) / 2.0
upper_band = basis + atr_mult * atr
lower_band = basis - atr_mult * atr
var float trend_dir = na
if na(trend_dir)
    trend_dir := 1
else if close > upper_band
    trend_dir := 1
else if close < lower_band
    trend_dir := -1
else
    trend_dir := trend_dir[1]
supertrend_line = trend_dir == 1 ? lower_band : upper_band
bullish_color = color.rgb(0, 102, 255)
bearish_color = color.rgb(255, 102, 178)
rma1_color = color.rgb(51, 153, 255)
rma2_color = color.rgb(255, 153, 204)
supertrend_color = trend_dir == 1 ? bullish_color : bearish_color
fill_color = color.new(supertrend_color, 80)
plot_rma1 = plot(rma1, color=rma1_color, title="RMA 1", linewidth=2)
plot_rma2 = plot(rma2, color=rma2_color, title="RMA 2", linewidth=2)
fill(plot_rma1, plot_rma2, color=color.new(color.silver, 85), title="RMA Fill")
plot_upper = plot(upper_band, color=color.new(color.gray, 50), title="Upper Band", linewidth=1)
plot_lower = plot(lower_band, color=color.new(color.gray, 50), title="Lower Band", linewidth=1)
fill(plot_upper, plot_lower, color=fill_color, title="SuperTrend Band Fill")
plot_st = plot(supertrend_line, color=supertrend_color, title="SuperTrend Line", linewidth=2, style=plot.style_line)
bullish_flip = ta.crossover(close, supertrend_line)
bearish_flip = ta.crossunder(close, supertrend_line)
plotshape(bullish_flip, title="Buy Signal", location=location.belowbar, color=bullish_color, style=shape.triangleup, size=size.small)
plotshape(bearish_flip, title="Sell Signal", location=location.abovebar, color=bearish_color, style=shape.triangledown, size=size.small)
alertcondition(bullish_flip, title="Buy Alert", message="RMA SuperTrend Buy Signal")
alertcondition(bearish_flip, title="Sell Alert", message="RMA SuperTrend Sell Signal")
barcolor(trend_dir == 1 ? bullish_color : bearish_color)

